home *** CD-ROM | disk | FTP | other *** search
/ L' Effet Pommier 3 / L'Effet Pommier - Volume 03.iso / Programmation / Gooey1.3.1 / C Templates / mmWindow.c < prev    next >
Text File  |  1994-05-26  |  38KB  |  1,075 lines

  1. $$Loop Windows
  2. $$Message MM Window, mm:mmW_$Worksheet.name$.c
  3.  
  4. $$File mm:mmW_$Worksheet.name$.c
  5. /*  mmW_$Worksheet.name$                                 Handle this Window */
  6. /*  $CopyRight$ */
  7.  
  8. /* 
  9.     File name: mmW_$Worksheet.name$.c
  10.     Function: Handle a Window 
  11.     History: $Date$ Original by $Author$
  12.  
  13. */
  14.  
  15. #include "mmCommon$Prototype.name$.h"    /* Common */
  16. #include "Common$Prototype.name$.h"        /* Common */
  17.  
  18. #include "$Worksheet.name$.h"                    /* The window specific file */
  19.  
  20. /* ======================================================= */
  21.  
  22. static void InitRecord($Worksheet.name$RecPtr theWS);
  23.  
  24. static void LocateInstance(WindowPtr theWindow);
  25.  
  26. /* Handle a button being pressed */
  27. static void Do_A_Button($Worksheet.name$RecPtr theWS,ControlHandle theControl);
  28.  
  29. $$if Worksheet.CheckboxesOrRadios
  30. /* Handle a checkbox being pressed */
  31. static void Do_A_Checkbox($Worksheet.name$RecPtr theWS,ControlHandle theControl);
  32.  
  33. $$endif
  34. $$if Worksheet.Scrollbars
  35. /* Handle a ScrollBar being pressed */
  36. static void Do_A_ScrollBar($Worksheet.name$RecPtr theWS,short code, ControlHandle theControl, Point myPt);
  37.  
  38. /* ======================================================= */
  39. /* ======================================================= */
  40.  
  41. /* Routine: Do_A_ScrollBar */
  42. /* Purpose: Handle a ScrollBar being pressed */
  43.  
  44. static void Do_A_ScrollBar($Worksheet.name$RecPtr theWS,short code,ControlHandle theControl,Point myPt)
  45. {
  46. long    RefCon;                                    /* RefCon for controls */
  47.  
  48.  
  49. RefCon = GetCRefCon(theControl);                /* get control refcon */
  50.  
  51. U_Scroll$Worksheet.name$(theWS,&RefCon,code, &myPt);    /* Allow for special handling of scrollbars */
  52.  
  53. switch (RefCon)                                    /* Select correct scrollbar */
  54.     {
  55.     $$Loop Control.type = ScrollBar
  56.     case ResC_$Control.name$:                    /* Scroll bar, $Control.FullName$  */
  57.         HandleWScrollBar(myPt,code,$Control.StepScroll$,$Control.PageScroll$,theControl);/*  code,Inc,PageInc,handle  */
  58.         break;
  59.  
  60.     $$EndLoop
  61.     $$Loop Control.type = UGauge
  62.     case ResC_$Control.name$:                    /* Plugin gauge, $Control.FullName$  */
  63.         HandleWScrollBar(myPt,code,$Control.StepScroll$,$Control.PageScroll$,theControl);/*  code,Inc,PageInc,handle  */
  64.         break;
  65.  
  66.     $$EndLoop
  67. $$if Worksheet.Document
  68. $$if Worksheet.ScrollHorz
  69.     case 12345L:
  70.         HandleWScrollBar(myPt,code,1,10,theControl);
  71.         break;
  72.  
  73. $$endif
  74. $$if Worksheet.ScrollVert
  75.     case 12346L:
  76.         HandleWScrollBar(myPt,code,1,10,theControl);
  77.         break;
  78.  
  79. $$endif
  80. $$endif Worksheet.Document
  81.     default:                                    /* allow other buttons, trap for debug */
  82.         break;                                    /* end of otherwise */
  83.     }                                            /* end of switch */
  84. }
  85.  
  86. $$endif
  87. /* ======================================================= */
  88. /* ======================================================= */
  89.  
  90. static void InitRecord($Worksheet.name$RecPtr theWS)
  91. {
  92.  
  93.  
  94. theWS->theWindow = nil;                    /* Make sure other routines know we are not valid yet */
  95.  
  96. $$if Worksheet.Document
  97. $$if Worksheet.ScrollHorz
  98. theWS->ScrollHHandle = nil;                /* Scrollbar is not valid yet */
  99. theWS->ScrollHLeftOffset = -1;            /* Offset of control from left side */
  100. $$endif
  101. $$if Worksheet.ScrollVert
  102. theWS->ScrollVHandle = nil;                /* Scrollbar is not valid yet */
  103. theWS->ScrollVTopOffset = -1;            /* Offset of control from top edge */
  104. $$endif
  105. $$endif Worksheet.Document
  106. /* Set the window back color */
  107. theWS->WindowBackColor.red  = 0x$Worksheet.RedBackColor$;  
  108. theWS->WindowBackColor.green  = 0x$Worksheet.GreenBackColor$;  
  109. theWS->WindowBackColor.blue  = 0x$Worksheet.BlueBackColor$;
  110.  
  111. $$Loop Control.type = Button
  112. theWS->Enable_$Control.name$ = $Control.Active$;                /* Button, $Control.FullName$  */
  113. $$EndLoop
  114. $$Loop Control.type = HotRect
  115. $$if Control.HotSpot
  116. theWS->Enable_$Control.name$ = $Control.Active$;                /* HotSpot, $Control.FullName$  */
  117. $$endif
  118. $$EndLoop
  119. $$Loop Control.type = Checkbox
  120. theWS->Enable_$Control.name$ = $Control.Active$;                /* Checkbox, $Control.FullName$  */
  121. $$if Control.Selected
  122. theWS->Value_$Control.name$ = 1;
  123. $$endif
  124. $$if Control.Unselected
  125. theWS->Value_$Control.name$ = 0;
  126. $$endif
  127. $$EndLoop
  128. $$Loop Control.type = Radio
  129. theWS->Enable_$Control.name$ = $Control.Active$;                /* Radio, $Control.FullName$  */
  130. $$if Control.Selected
  131. theWS->Value_$Control.name$ = 1;
  132. $$endif
  133. $$if Control.Unselected
  134. theWS->Value_$Control.name$ = 0;
  135. $$endif
  136. $$EndLoop
  137. $$Loop Control.type = ScrollBar
  138. theWS->Enable_$Control.name$ = $Control.Active$;                /* ScrollBar, $Control.FullName$  */
  139. theWS->Value_$Control.name$ = $Control.ValueScroll$;
  140. $$EndLoop
  141. $$Loop Control.type = Icon
  142. $$if Control.NonGraphic
  143. theWS->Enable_$Control.name$ = $Control.Active$;                /* Icon button, $Control.FullName$  */
  144. $$endif
  145. $$EndLoop
  146. $$Loop Control.type = Sicn
  147. $$if Control.NonGraphic
  148. theWS->Enable_$Control.name$ = $Control.Active$;                /* Sicn button, $Control.FullName$  */
  149. $$endif
  150. $$EndLoop
  151. $$Loop Control.type = Picture
  152. $$if Control.NonGraphic
  153. theWS->Enable_$Control.name$ = $Control.Active$;                /* Picture button, $Control.FullName$  */
  154. $$endif
  155. $$EndLoop
  156. $$Loop Control.type = UButton
  157. theWS->Enable_$Control.name$ = $Control.Active$;                /* Plugin button, $Control.FullName$  */
  158. $$EndLoop
  159. $$Loop Control.type = UToggle
  160. theWS->Enable_$Control.name$ = $Control.Active$;                /* Plugin toggle, $Control.FullName$  */
  161. $$if Control.Selected
  162. theWS->Value_$Control.name$ = 1;
  163. $$endif
  164. $$if Control.Unselected
  165. theWS->Value_$Control.name$ = 0;
  166. $$endif
  167. $$EndLoop
  168. $$Loop Control.type = UGauge
  169. theWS->Enable_$Control.name$ = $Control.Active$;                /* Plugin gauge, $Control.FullName$  */
  170. theWS->Value_$Control.name$ = $Control.ValueScroll$;
  171. $$EndLoop
  172. $$Loop Control.type = Popup
  173. theWS->Enable_$Control.name$ = $Control.Active$;                /* Popup menu, $Control.FullName$  */
  174. theWS->Value_$Control.name$ = $Control.SelectedID$;
  175. $$EndLoop
  176. $$Loop Control.type = Palette
  177. theWS->Enable_$Control.name$ = $Control.Active$;                /* Palette, $Control.FullName$  */
  178. theWS->Value_$Control.name$ = $Control.ValueScroll$;
  179. $$EndLoop
  180. $$Loop Control.type = List
  181. theWS->List_$Control.name$ = nil;                                /* List, $Control.FullName$ */
  182. SetRect(&theWS->ListRect_$Control.name$,$Control.LeftPosition$,$Control.TopPosition$,$Control.RightPosition$,$Control.BottomPosition$);                /* left,top,right,bottom */
  183. $$EndLoop
  184. $$Loop Control.type = EditText
  185. theWS->TE_$Control.name$ = nil;                                /* Edit Text, $Control.FullName$ */
  186. SetRect(&theWS->TERect_$Control.name$,$Control.LeftPosition$,$Control.TopPosition$,$Control.RightPosition$,$Control.BottomPosition$);                /* left,top,right,bottom */
  187. GetIndString(theWS->TEStr_$Control.name$,sResC_$Control.name$,1);/*  ...Edit text, default value  */
  188. $$EndLoop
  189.  
  190. U_Init$Worksheet.name$Rec(theWS);                            /* Call user init routine */
  191. }
  192.  
  193. /* ======================================================= */
  194.  
  195. static void LocateInstance(WindowPtr theWindow)
  196. {
  197. $Worksheet.name$RecPtr        ckWS,theWS;
  198.  
  199.  
  200. theWS = nil;                            /* Init to not found */
  201. ckWS = ListRecPtr_$Worksheet.name$;
  202. while (ckWS != nil)
  203.     {
  204.     if (ckWS->theWindow == theWindow)
  205.         theWS = ckWS;
  206.     ckWS = ckWS->Next;
  207.     }
  208. RecPtr_$Worksheet.name$ = theWS;
  209. }
  210.  
  211. /* ======================================================= */
  212.  
  213. /* Routine: Init_$Worksheet.name$ */
  214. /* Purpose: Initialize our window data to not in use yet */
  215.  
  216. void Init_$Worksheet.name$(void)
  217. {
  218.  
  219.  
  220. $$if Worksheet.SavePosition
  221. theWindowLocRec.Loc_$Worksheet.name$.h = $Worksheet.LeftPosition$;            /* Set default Horz position */
  222. theWindowLocRec.Loc_$Worksheet.name$.v = $Worksheet.TopPosition$;            /* Set default Vert position */
  223.  
  224. $$endif Worksheet.SavePosition
  225. RecPtr_$Worksheet.name$ = nil;                        /* No open windows yet */
  226. ListRecPtr_$Worksheet.name$ = nil;
  227. MultipleAllowed_$Worksheet.name$ = true;            /* Init to allow multiple instances */
  228.  
  229. U_Init$Worksheet.name$();                            /* Call the user window init routine */
  230. }
  231.  
  232. /* ======================================================= */
  233.  
  234. /* Routine: Close_$Worksheet.name$ */
  235. /* Purpose: Close out the window */
  236.  
  237. void Close_$Worksheet.name$(WindowPtr whichWindow)
  238. {
  239. $Worksheet.name$RecPtr        ckWS,theWS;
  240.  
  241.  
  242. if (whichWindow == (WindowPtr)-1)
  243.     whichWindow = FrontWindow();
  244.     
  245. LocateInstance(whichWindow);
  246.  
  247. /* See if we should close this window */
  248. if (RecPtr_$Worksheet.name$ != nil)
  249.     {
  250.     theWS = RecPtr_$Worksheet.name$;
  251.     
  252.     U_Close$Worksheet.name$(theWS);                    /* Call the user window close routine */
  253.  
  254.     $$Loop Control.type = EditText
  255.     if (theInput == theWS->TE_$Control.name$)        /* See if this Text Edit field handle */
  256.         theInput = nil;                                /* Clear the handle used */
  257.     $$if Control.Global
  258.     Get_TE_String(theWS->TE_$Control.name$,(Str255 *)&theWS->TEStr_$Control.name$);
  259.     $$endif Control.Global
  260.     TEDispose(theWS->TE_$Control.name$);            /* Dispose of a List, $Control.FullName$ */
  261.  
  262.     $$EndLoop
  263.     $$Loop Control.type = List
  264.     LDispose(theWS->List_$Control.name$);            /* Dispose of a List, $Control.FullName$ */
  265.  
  266.     $$EndLoop
  267.     $$if Worksheet.SavePosition
  268.     SetPort(whichWindow);                            /* Select our window */
  269.     theWindowLocRec.Loc_$Worksheet.name$.h = 0;        /* Reset Horz position */
  270.     theWindowLocRec.Loc_$Worksheet.name$.v = 0;        /* Reset Vert position */
  271.     LocalToGlobal(&theWindowLocRec.Loc_$Worksheet.name$);    /* Get global location */
  272.  
  273.     $$endif Worksheet.SavePosition
  274.     Mk_CloseLayeredWindow(whichWindow);                /* Notify the layer code that we are closing */
  275.  
  276.     DisposeWindow(whichWindow);                        /* Clear window and controls */
  277.  
  278.  
  279.     ckWS = ListRecPtr_$Worksheet.name$;
  280.     if (ckWS == theWS)                                /* See if first in the list */
  281.         {
  282.         ListRecPtr_$Worksheet.name$ = theWS->Next;    /* Use second one as new first */
  283.         DisposePtr((Ptr)theWS);                        /* Get rid of this one */
  284.         }
  285.     else
  286.         {
  287.         while (ckWS != nil)                            /* Loop thru them all */
  288.             {
  289.             if (ckWS->Next == theWS)                /* See if the next one is a match */
  290.                 {
  291.                 ckWS->Next = theWS->Next;            /* Get new next one */
  292.                 DisposePtr((Ptr)theWS);                /* Get rid of this one */
  293.                 ckWS = nil;                            /* Get us out of the loop */
  294.                 }
  295.             else
  296.                 ckWS = ckWS->Next;                    /* Try the next one */
  297.             }
  298.         }
  299.  
  300.     RecPtr_$Worksheet.name$ = nil;                    /* No active one */
  301.  
  302.     $$Link    Worksheet.Close
  303.     }
  304. }
  305.  
  306. /* ======================================================= */
  307.  
  308. /* Routine: Resized_$Worksheet.name$ */
  309. /* Purpose: We were resized or zoomed, update the scrolling scrollbars */
  310.  
  311. void Resized_$Worksheet.name$(Rect *OldRect,WindowPtr whichWindow)
  312. {
  313. WindowPtr    SavePort;                                /* Place to save the last port */
  314. Rect        temp2Rect;                                /* temp rectangle */
  315. short        Index;                                    /* temp integer */
  316. ControlHandle    ScrollHandle;
  317. $Worksheet.name$RecPtr        theWS;
  318.  
  319.  
  320. LocateInstance(whichWindow);
  321.  
  322. if (RecPtr_$Worksheet.name$ != nil)                    /* Only do if the window is us */
  323.     {
  324.     theWS = RecPtr_$Worksheet.name$;
  325.     
  326.     GetPort(&SavePort);                                /* Save the current port */
  327.     SetPort(whichWindow);                            /* Set the port to my window */
  328.  
  329.     U_Resized$Worksheet.name$(theWS,OldRect);        /* Call the user window resized routine */
  330.  
  331.     $$if Worksheet.Document
  332.     temp2Rect = theWS->theWindow->portRect;    /* Get the window rectangle */
  333.     EraseRect(&temp2Rect);                            /* Erase the new window area */
  334.     InvalRect(&temp2Rect);                            /* Set to update the new window area */
  335.  
  336. $$if Worksheet.ScrollHorz
  337.     if (theWS->ScrollHHandle != nil)                /* Only do if the control is valid */
  338.         {
  339.         ScrollHandle = theWS->ScrollHHandle;
  340.         HLock((Handle)ScrollHandle);                /* Lock the handle while we use it */
  341.         tempRect = (*ScrollHandle)->contrlRect;        /* Get the last control position */
  342.         tempRect.top = tempRect.top - 4;            /* Widen the area to update */
  343.         tempRect.right = tempRect.right + 16;        /* Widen the area to update */
  344.         InvalRect(&tempRect);                        /* Flag old position for update routine */
  345.         tempRect = (*ScrollHandle)->contrlRect;        /* Get the last control position */
  346.         temp2Rect = whichWindow->portRect;            /*  Get the window rectangle */
  347.         Index = temp2Rect.right - temp2Rect.left - 13;/* Get the scroll area width */
  348.         tempRect.left = theWS->ScrollHLeftOffset;    
  349.         HideControl(ScrollHandle);                    /* Hide it during size and move */
  350.         SizeControl(ScrollHandle, Index,16);        /* Make it 16 pixels high, std width */
  351.         MoveControl(ScrollHandle,tempRect.left,temp2Rect.bottom - temp2Rect.top-15);/* Size it correctly */
  352.         ShowControl(ScrollHandle);                    /* Safe to show it now */
  353.         HUnlock((Handle)ScrollHandle);                /* Let it float again */
  354.         }
  355.  
  356. $$endif
  357. $$if Worksheet.ScrollVert
  358.     if (theWS->ScrollVHandle != nil)                /* Only do if the control is valid */
  359.         {
  360.         ScrollHandle = theWS->ScrollVHandle;
  361.         HLock((Handle)ScrollHandle);                /* Lock the handle while we use it */
  362.         tempRect = (*ScrollHandle)->contrlRect;        /* Get the last control position */
  363.         tempRect.left = tempRect.left - 4;            /* Widen the area to update */
  364.         tempRect.bottom = tempRect.bottom + 16;        /* Widen the area to update */
  365.         InvalRect(&tempRect);                        /* Flag old position for update routine */
  366.         tempRect = (*ScrollHandle)->contrlRect;        /* Get the last control position */
  367.         temp2Rect = whichWindow->portRect;            /*  Get the window rectangle */
  368.         Index = temp2Rect.bottom - temp2Rect.top - 13;/* Get the scroll area height */
  369.         tempRect.top = theWS->ScrollVTopOffset;
  370.         HideControl(ScrollHandle);                    /* Hide it during size and move */
  371.         SizeControl(ScrollHandle,16,Index);            /* Make it 16 pixels high, std height */
  372.         MoveControl(ScrollHandle,temp2Rect.right - temp2Rect.left-15,tempRect.top);/* Size it correctly */
  373.         ShowControl(ScrollHandle);                    /* Safe to show it now */
  374.         HUnlock((Handle)ScrollHandle);                /* Let it float again */
  375.         }
  376.  
  377. $$endif
  378.     $$endif Worksheet.Document
  379.     SetPort(SavePort);                                /* Restore the old port */
  380.     }
  381. }
  382.  
  383. /* ======================================================= */
  384.  
  385. /* Routine: Update_$Worksheet.name$ */
  386. /* Purpose: Update our window */
  387.  
  388. void Update_$Worksheet.name$(WindowPtr whichWindow)
  389. {
  390. WindowPtr    SavePort;                            /* Place to save the last port */
  391. $$if Worksheet.Icons
  392. Handle        Icon_Handle;                        /* Handle used in displaying icons */
  393. $$endif Worksheet.Icons
  394. $$if Worksheet.Pictures
  395. PicHandle    Pic_Handle;                            /* Handle used in displaying pictures */
  396. $$endif Worksheet.Pictures
  397. RGBColor    Saved_ForeColor;                    /* Place to save colors */
  398. RGBColor    Saved_BackColor;                    /* Place to save colors */
  399. RGBColor    DrawingColor;                        /* Place to make colors */
  400. $Worksheet.name$RecPtr        theWS;
  401.  
  402.  
  403. LocateInstance(whichWindow);
  404.  
  405. if (RecPtr_$Worksheet.name$ != nil)                    /* Only do if the window is us */
  406.     {
  407.     theWS = RecPtr_$Worksheet.name$;
  408.  
  409.     GetPort(&SavePort);                            /* Save the current port */
  410.     SetPort(whichWindow);                        /* Set the port to my window */
  411.  
  412.     $$if Worksheet.HasControls
  413.     if (Has.ColorQD)                                /* See if color QuickDraw is around */
  414.         {
  415.         GetForeColor(&Saved_ForeColor);            /* Save the fore color */
  416.         GetBackColor(&Saved_BackColor);            /* Save the back color */
  417.  
  418.         RGBForeColor(&Black_ForeColor);            /* Set the fore color to Black */
  419.         RGBBackColor(&White_BackColor);            /* Set the back color to White */
  420.         }                                        /* End of IF */
  421.  
  422.  
  423.     $$Set TextSize = 12
  424.     $$Set TextFont = applFont
  425.     $$Set TextStyle = 0
  426. $$Loop Control.type = StaticText
  427.     /* Draw static text, $Control.FullName$ */
  428.     $$if Control.TextColor ! Black
  429.     if (Has.ColorQD)                                        /* See if color QuickDraw is around */
  430.         {
  431.         DrawingColor.red = 0x$Control.RedTextColor$;
  432.         DrawingColor.green = 0x$Control.GreenTextColor$;
  433.         DrawingColor.blue = 0x$Control.BlueTextColor$;
  434.         RGBForeColor(&DrawingColor);                    /* Set the fore color */
  435.         RGBBackColor(&Saved_BackColor);                    /* Set the back color */
  436.         }
  437.     $$endif Control.TextColor
  438.     $$if Control.MultipleLine
  439.     SetRect(&tempRect,$Control.LeftPosition$,$Control.TopPosition$,$Control.RightPosition$,$Control.BottomPosition$);
  440.     DrawStaticTextBox(sResC_$Control.name$,&tempRect,$Control.TextAlignment$,$Control.TextSize$,$Control.TextFont$,$Control.TextStyle$);
  441.     $$endif Control.MultipleLine
  442.     $$if Control.SingleLine
  443.     DrawStaticLine(sResC_$Control.name$,$Control.LeftPosition$,$Control.TopPosition$,$Control.TextSize$,$Control.TextFont$,$Control.TextStyle$);
  444.     $$endif Control.SingleLine
  445.     $$if Control.TextColor ! Black
  446.     if (Has.ColorQD)                                    /* See if color QuickDraw is around */
  447.         {
  448.         RGBForeColor(&Black_ForeColor);                    /* Set the fore color */
  449.         RGBBackColor(&White_BackColor);                    /* Set the back color */
  450.         }
  451.     $$endif Control.TextColor
  452.  
  453. $$EndLoop
  454. $$Loop Control.type = Icon
  455.     $$if Control.Graphic
  456.     /* Draw an Icon */
  457.     Icon_Handle = GetIcon(ResC_N_$Control.name$);        /* Get Icon into memory */
  458.     SetRect(&tempRect,$Control.LeftPosition$,$Control.TopPosition$,$Control.RightPosition$,$Control.BottomPosition$);
  459.     if (Icon_Handle != nil)                                /* Only use handle if it is valid */
  460.         PlotIcon(&tempRect,Icon_Handle);                /* Draw the icon in the window */
  461.  
  462.     $$endif Control.Graphic
  463. $$EndLoop
  464. $$Loop Control.type = Sicn
  465.     $$if Control.Graphic
  466.     /* Draw an sicn */
  467.     SetRect(&tempRect,$Control.LeftPosition$,$Control.TopPosition$,$Control.RightPosition$,$Control.BottomPosition$);
  468.     Plot_Sicn(ResC_N_$Control.name$, &tempRect);        /* Draw the sicn */
  469.  
  470.     $$endif Control.Graphic
  471. $$EndLoop
  472. $$Loop Control.type = Picture
  473.     $$if Control.Graphic
  474.     /* Draw the Picture */
  475.     Pic_Handle = GetPicture(ResC_N_$Control.name$);    /* Get Picture into memory */
  476.     SetRect(&tempRect,$Control.LeftPosition$,$Control.TopPosition$,$Control.RightPosition$,$Control.BottomPosition$);
  477.     $$if Control.ClipPicture
  478.     if (Pic_Handle != nil)                            /* Only use handle if it is valid */
  479.         {
  480.         ClipRect(&tempRect);                        /* Clip picture to this rectangle */
  481.         HLock((Handle)Pic_Handle);                    /* Lock the handle before using it */
  482.         tempRect.right = tempRect.left + ((*Pic_Handle)->picFrame.right - (*Pic_Handle)->picFrame.left);
  483.         tempRect.bottom = tempRect.top + ((*Pic_Handle)->picFrame.bottom - (*Pic_Handle)->picFrame.top);
  484.         HUnlock((Handle)Pic_Handle);                /* Unlock the picture again */
  485.         }
  486.     $$endif Control.ClipPicture
  487.     if (Pic_Handle != nil)                            /* Only use handle if it is valid */
  488.         DrawPicture(Pic_Handle, &tempRect);            /* Draw this picture */
  489.     $$if Control.ClipPicture
  490.     SetRect(&tempRect, 0, 0, 32000, 32000);            /* Widen the clip area again */
  491.     ClipRect(&tempRect);                            /* Set the clip area */
  492.     $$endif Control.ClipPicture
  493.     $$endif Control.Graphic
  494.  
  495. $$EndLoop
  496. $$Loop Control.type = EditText
  497.     /* Draw Edit text */
  498.     $$if Control.TextColor ! Black
  499.     if (Has.ColorQD)                                        /* See if color QuickDraw is around */
  500.         {
  501.         DrawingColor.red = 0x$Control.RedTextColor$;
  502.         DrawingColor.green = 0x$Control.GreenTextColor$;
  503.         DrawingColor.blue = 0x$Control.BlueTextColor$;
  504.         RGBForeColor(&DrawingColor);                    /* Set the fore color */
  505.         RGBBackColor(&Saved_BackColor);                    /* Set the back color */
  506.         }
  507.     $$endif Control.TextColor
  508.     DrawTheTEArea(&theWS->TERect_$Control.name$,theWS->TE_$Control.name$,$Control.TextSize$,$Control.TextFont$,$Control.TextStyle$);
  509.     $$if Control.TextColor ! Black
  510.     if (Has.ColorQD)                                        /* See if color QuickDraw is around */
  511.         {
  512.         RGBForeColor(&Black_ForeColor);                    /* Set the fore color */
  513.         RGBBackColor(&White_BackColor);                    /* Set the back color */
  514.         }
  515.     $$endif Control.TextColor
  516.     
  517. $$EndLoop
  518. $$Loop Control.type = Line
  519.     /* Draw a line, $Control.FullName$ */
  520.     $$if Control.GrayLine
  521.     PenPat(&qd.gray);                                        /* Set the gray pen pattern */
  522.     $$endif Control.GrayLine
  523.     $$if Control.LineWidth ! 1
  524.     PenSize($Control.LineWidth$,$Control.LineWidth$);
  525.     $$endif Control.LineWidth
  526.     MoveTo($Control.LeftPosition$,$Control.TopPosition$);        /* Horz,vert, Move to starting position */
  527.     LineTo($Control.RightPosition$,$Control.BottomPosition$);    /* Horz,vert, Draw to the ending position */
  528.     $$if Control.LineWidth ! 1
  529.     PenSize(1,1);
  530.     $$endif Control.LineWidth
  531.     $$if Control.GrayLine
  532.     PenPat(&qd.black);                                        /*  Back to default pen pattern  */
  533.     $$endif Control.GrayLine
  534.  
  535. $$EndLoop
  536. $$Loop Control.type = List
  537.     /* Update a List */
  538.     UpdateTheList(theWS->theWindow->visRgn,theWS->List_$Control.name$,&theWS->ListRect_$Control.name$,
  539.         $Control.TextSize$,$Control.TextFont$,$Control.TextStyle$,false);
  540.  
  541. $$EndLoop
  542.  
  543.     if (Has.ColorQD)                                /* See if color QuickDraw is around */
  544.         {
  545.         RGBForeColor(&Saved_ForeColor);            /* Restore the fore color */
  546.         RGBBackColor(&Saved_BackColor);            /* Restore the back color */
  547.         }                                        /* End of IF */
  548.  
  549.     $$endif Worksheet.HasControls
  550.  
  551.     TextFont(applFont);                            /* Back to the application font */
  552.     TextSize(12);                                /* Back to the application size */
  553.     TextFace(0);                                /* Set text style */
  554.  
  555.     U_Update$Worksheet.name$(theWS);            /* Call the user window update routine */
  556.  
  557.     $$if Worksheet.Document
  558.     DrawGrowIcon(theWS->theWindow);                /* Draw the Grow box */
  559.  
  560.     $$endif Worksheet.Document
  561.     SetPort(SavePort);                            /* Restore the old port */
  562.     }
  563. }
  564.  
  565. /* ======================================================= */
  566.  
  567. /* Routine: Open_$Worksheet.name$ */
  568. /* Purpose: Open our window */
  569.  
  570. void Open_$Worksheet.name$(void)
  571. {
  572. $$if Worksheet.Document
  573. Rect        temp2Rect;                                /* Used for scrollbar placement */
  574. short        ScrollAreaHeight;                        /* Used for scrollbar placement */
  575. short        ScrollAreaWidth;                        /* Used for scrollbar placement */
  576. $$endif
  577. WindowPtr    BehindWindow;                            /* Used for window placement */
  578. long        theLong;                                /* Used for icons and hotspots definition */
  579. $$if Worksheet.SavePosition
  580. Point        DefaultPosition;                        /* Used for window placement */
  581. $$endif
  582. $Worksheet.name$RecPtr        theWS;
  583.  
  584.  
  585. if ((ListRecPtr_$Worksheet.name$ == nil) || (MultipleAllowed_$Worksheet.name$))
  586.     {
  587.     theWS = ($Worksheet.name$RecPtr)NewPtrClear(sizeof($Worksheet.name$Rec));
  588.     RecPtr_$Worksheet.name$ = theWS;
  589.     theWS->Next = ListRecPtr_$Worksheet.name$;
  590.     ListRecPtr_$Worksheet.name$ = theWS;
  591.     
  592.     InitRecord(theWS);
  593.  
  594.     BehindWindow = Mk_BehindWindow($Worksheet.Layer$);        /* Get which window to place below */
  595.  
  596.     if (Has.ColorQD)                                /* See if color QuickDraw is around */
  597.         theWS->theWindow = GetNewCWindow(ResW_$Worksheet.name$,nil,BehindWindow);/* Get the COLOR window from the resource file */
  598.     else
  599.         theWS->theWindow = GetNewWindow(ResW_$Worksheet.name$,nil,BehindWindow);/* Get the window from the resource file */
  600.     Mk_RegisterWindow(theWS->theWindow,$Worksheet.Layer$);    /* Register the window with the layers */
  601.     SetPort(theWS->theWindow);                        /* Prepare to write into our window */
  602.  
  603.     $$if Worksheet.Center
  604.     tempRect = theWS->theWindow->portRect;            /* Get the windows position and size */
  605.     $$if Worksheet.CenterHorz
  606.     tempRect.left = ((screenRect.bounds.right - screenRect.bounds.left) - (tempRect.right - tempRect.left)) / 2;    /* Center Horz */
  607.     $$endif Worksheet.CenterHorz
  608.     $$if Worksheet.CenterVert
  609.     tempRect.top = ((screenRect.bounds.bottom - screenRect.bounds.top) - (tempRect.bottom - tempRect.top)) / 3;    /* 1/3 vert */
  610.     if (tempRect.top < 40)                            /* Keep below the menu bar */
  611.         tempRect.top = 40;
  612.     $$endif Worksheet.CenterVert
  613.     MoveWindow(theWS->theWindow,tempRect.left,tempRect.top,true);
  614.     $$endif
  615.  
  616. $$Loop Control.type = Button
  617.     /* Make a button */
  618.     theWS->Ctrl_$Control.name$ = MakeNormalControl(theWS->theWindow,ResC_$Control.name$,theWS->Enable_$Control.name$,0);
  619.  
  620. $$EndLoop Control.type = Button
  621. $$Loop Control.type = Checkbox
  622.     /* Make a checkbox */
  623.     theWS->Ctrl_$Control.name$ = MakeNormalControl(theWS->theWindow,ResC_$Control.name$,
  624.         theWS->Enable_$Control.name$,theWS->Value_$Control.name$);
  625.  
  626. $$EndLoop Control.type = Checkbox
  627. $$Loop Control.type = Radio
  628.     /* Make a Radio */
  629.     theWS->Ctrl_$Control.name$ = MakeNormalControl(theWS->theWindow,ResC_$Control.name$,
  630.         theWS->Enable_$Control.name$,theWS->Value_$Control.name$);
  631.  
  632. $$EndLoop Control.type = Radio
  633. $$Loop Control.type = HotRect
  634.     /* Make a HotSpot/rect */
  635.     theWS->Ctrl_$Control.name$ = MakeHotSpot(theWS->theWindow,ResC_$Control.name$,
  636.         $Control.MakeHotSpot$,$Control.LineWidth$,$Control.ShadowWidth$,sResC_$Control.name$,theWS->Enable_$Control.name$);
  637.     theWS->Rect_$Control.name$ = (*(theWS->Ctrl_$Control.name$))->contrlRect;    /* Get the position */
  638.  
  639. $$EndLoop Control.type = HotRect
  640. $$Loop Control.type = List
  641.     /* Make a List */
  642.     Make_A_List(&theWS->List_$Control.name$,&theWS->ListRect_$Control.name$,
  643.         theWS->theWindow,ResC_$Control.name$,$Control.TextSize$,$Control.TextFont$,$Control.TextStyle$,false);
  644.     
  645. $$EndLoop Control.type = List
  646. $$Loop Control.type = EditText
  647.     /* Open a TE box, $Control.FullName$ */
  648.     Make_TE_Area(&theWS->TE_$Control.name$,&theWS->TERect_$Control.name$,$Control.TextSize$,$Control.TextFont$,sResC_$Control.name$);/* Make the TE */
  649.     TESetText(&theWS->TEStr_$Control.name$[1],theWS->TEStr_$Control.name$[0],theWS->TE_$Control.name$);
  650.  
  651. $$EndLoop Control.type = EditText
  652. $$Loop Control.type = Icon
  653.     $$if Control.NonGraphic
  654.     /* Make an icon button */
  655.     theWS->Ctrl_$Control.name$ = MakeIconSicn(theWS->theWindow,ResC_$Control.name$,
  656.         theWS->Enable_$Control.name$,ResC_N_$Control.name$,ResC_H_$Control.name$);
  657.  
  658.     $$endif Control.NonGraphic
  659. $$EndLoop Control.type = Icon
  660. $$Loop Control.type = Sicn
  661.     $$if Control.NonGraphic
  662.     /* Make an sicn button */
  663.     theWS->Ctrl_$Control.name$ = MakeIconSicn(theWS->theWindow,ResC_$Control.name$,
  664.         theWS->Enable_$Control.name$,ResC_N_$Control.name$,ResC_H_$Control.name$);
  665.  
  666.     $$endif Control.NonGraphic
  667. $$EndLoop Control.type = Sicn
  668. $$Loop Control.type = Picture
  669.     $$if Control.NonGraphic
  670.     /* Make an picture button */
  671.     theWS->Ctrl_$Control.name$ = MakePlugin(theWS->theWindow,ResC_$Control.name$,
  672.     $$if Control.ClipPicture
  673.         theWS->Enable_$Control.name$,ResC_N_$Control.name$,1,0,0);    /* Clipped */
  674.     $$endif Control.ClipPicture
  675.     $$if Control.ResizePicture
  676.         theWS->Enable_$Control.name$,ResC_N_$Control.name$,0,0,0);    /* Resized */
  677.     $$endif Control.ResizePicture
  678.  
  679.     $$endif Control.NonGraphic
  680. $$EndLoop Control.type = Picture
  681. $$Loop Control.type = ScrollBar
  682.     /* Make a scroll bar */
  683.     theWS->Ctrl_$Control.name$ = GetNewControl(ResC_$Control.name$,theWS->theWindow);/* Make a new scrollbar */
  684.     if (theWS->Enable_$Control.name$)
  685.         HiliteControl(theWS->Ctrl_$Control.name$,0);            /* Enable the ScrollBar */
  686.     else
  687.         HiliteControl(theWS->Ctrl_$Control.name$,255);            /* Disable the ScrollBar */
  688.     MakeMinMaxValue(theWS->Ctrl_$Control.name$,$Control.MinScroll$,$Control.MaxScroll$,theWS->Value_$Control.name$);
  689.  
  690. $$EndLoop Control.type = ScrollBar
  691. $$Loop Control.type = Popup
  692.     /* Make a Popup Menu */
  693.     theWS->Ctrl_$Control.name$ = MakePopupMenu(theWS->theWindow,ResC_$Control.name$,
  694.         theWS->Enable_$Control.name$,mResC_$Control.name$,theWS->Value_$Control.name$);
  695.  
  696. $$EndLoop Control.type = Popup
  697. $$Loop Control.type = Palette
  698.     /* Make a Palette */
  699.     theWS->Ctrl_$Control.name$ = MakePalette(theWS->theWindow,ResC_$Control.name$,
  700.         theWS->Enable_$Control.name$,$Control.NumRows$,$Control.NumColumns$,ResC_N_$Control.name$,$Control.HMethod$);
  701.  
  702. $$EndLoop Control.type = Palette
  703. $$Loop Control.type = UButton
  704.     /* Make a plugin button */
  705.     theWS->Ctrl_$Control.name$ = MakePlugin(theWS->theWindow,ResC_$Control.name$,
  706.         theWS->Enable_$Control.name$,ResC_N_$Control.name$,ResC_H_$Control.name$,0,0);
  707.  
  708. $$EndLoop Control.type = UButton
  709. $$Loop Control.type = UToggle
  710.     /* Make a plugin toggle, $Control.FullName$ */
  711.     theWS->Ctrl_$Control.name$ = MakePlugin(theWS->theWindow,ResC_$Control.name$,
  712.         theWS->Enable_$Control.name$,ResC_N_$Control.name$,ResC_H_$Control.name$,0,theWS->Value_$Control.name$);
  713.  
  714. $$EndLoop Control.type = UToggle
  715. $$Loop Control.type = UGauge
  716.     /* Make a plugin gauge, $Control.FullName$ */
  717.     theWS->Ctrl_$Control.name$ = MakePlugin(theWS->theWindow,ResC_$Control.name$,
  718.         theWS->Enable_$Control.name$,ResC_N_$Control.name$,ResC_H_$Control.name$,0,theWS->Value_$Control.name$);
  719.     MakeMinMaxValue(theWS->Ctrl_$Control.name$,$Control.MinScroll$,$Control.MaxScroll$,theWS->Value_$Control.name$);
  720.  
  721. $$EndLoop Control.type = UGauge
  722.  
  723. $$if Worksheet.Document
  724. $$if Worksheet.ScrollHorz
  725.     SetRect(&tempRect,1,1,1,1);
  726.     theWS->ScrollHHandle = NewControl(theWS->theWindow,&tempRect,"\pHorz Scroll",true,1,1,100,scrollBarProc,12345L);
  727.     Resized_$Worksheet.name$(&tempRect,theWS->theWindow);
  728.     HiliteControl(theWS->ScrollHHandle,255);
  729. $$endif
  730. $$if Worksheet.ScrollVert
  731.     SetRect(&tempRect,1,1,1,1);
  732.     theWS->ScrollVHandle = NewControl(theWS->theWindow,&tempRect,"\pVert Scroll",true,1,1,100,scrollBarProc,12346L);
  733.     Resized_$Worksheet.name$(&tempRect,theWS->theWindow);
  734.     HiliteControl(theWS->ScrollVHandle,255);
  735. $$endif
  736. $$endif Worksheet.Document
  737.  
  738.     $$if Worksheet.SavePosition
  739.     SetPort(theWS->theWindow);                        /* Select our window */
  740.     DefaultPosition.h = 0;                            /* Reset Horz position */
  741.     DefaultPosition.v = 0;                            /* Reset Vert position */
  742.     LocalToGlobal(&DefaultPosition);                /* Get global location */
  743.     PositionWindow(theWS->theWindow,theWindowLocRec.Loc_$Worksheet.name$,DefaultPosition);
  744.  
  745.     $$endif Worksheet.SavePosition
  746.  
  747.     U_Open$Worksheet.name$(theWS);                    /* Call the users window open routine */
  748.  
  749.     ShowWindow(theWS->theWindow);                    /* Show the window now */
  750.  
  751.     $$Link    Worksheet.Open
  752.     }
  753. else
  754.     theWS = ListRecPtr_$Worksheet.name$;
  755.  
  756. Mk_HiliteWindow(theWS->theWindow);                    /* Already open, so show it */
  757. }
  758.  
  759. /* ======================================================= */
  760.  
  761. /* Routine: Activate_$Worksheet.name$ */
  762. /* Purpose: We activated or deactivated */
  763.  
  764. void Activate_$Worksheet.name$(WindowPtr whichWindow,Boolean Do_An_Activate)
  765. {
  766. WindowPtr    SavePort;                                /* Place to save the last port */
  767. $Worksheet.name$RecPtr        theWS;
  768.  
  769.  
  770. LocateInstance(whichWindow);
  771.  
  772. if (RecPtr_$Worksheet.name$ != nil)                    /* Only do if the window is us */
  773.     {
  774.     theWS = RecPtr_$Worksheet.name$;
  775.  
  776.     GetPort(&SavePort);                                /* Save the current port */
  777.     SetPort(whichWindow);                            /* Set the port to my window */
  778.  
  779.     $$if Worksheet.Document
  780.     DrawGrowIcon(whichWindow);                        /* Draw the Grow box */
  781.  
  782.     $$endif Worksheet.Document
  783.     if (!Do_An_Activate)                            /* Handle the deactivate */
  784.         {
  785.         if (theInput != nil)                        /* See if there is already a TE area */
  786.             TEDeactivate(theInput);                    /* Yes, so turn it off */
  787.         theInput = nil;                                /* Deactivate the TE area */
  788. $$if Worksheet.Document
  789. $$if Worksheet.ScrollHorz
  790.         HiliteControl(theWS->ScrollHHandle,255);
  791. $$endif
  792. $$if Worksheet.ScrollVert
  793.         HiliteControl(theWS->ScrollVHandle,255);
  794. $$endif
  795. $$endif Worksheet.Document
  796.         $$Link    Worksheet.Deactivate
  797.         }
  798.     else
  799.         {
  800. $$if Worksheet.Document
  801. $$if Worksheet.ScrollHorz
  802.         HiliteControl(theWS->ScrollHHandle,0);
  803. $$endif
  804. $$if Worksheet.ScrollVert
  805.         HiliteControl(theWS->ScrollVHandle,0);
  806. $$endif
  807. $$endif Worksheet.Document
  808.         $$Link    Worksheet.Activate
  809.         }
  810.  
  811.     U_Activate$Worksheet.name$(theWS,Do_An_Activate);    /* Call the user window activate routine */
  812.  
  813.     SetPort(SavePort);                                /* Restore the old port */
  814.     }
  815. }
  816.  
  817. /* ======================================================= */
  818.  
  819. /* Routine: Do_A_Button */
  820. /* Purpose: Handle a button pressed */
  821.  
  822. static void Do_A_Button($Worksheet.name$RecPtr theWS,ControlHandle theControl)    /* Handle a button being pressed */
  823. {
  824. long        RefCon;                                    /* RefCon for controls */
  825. short        UnHiliteValue;                            /* For unhilite */
  826. short        theSelection;                            /* For palettes and popups */
  827.  
  828.  
  829. if (theWS != nil)                                    /* Only do if the window is us */
  830.     {
  831.  
  832.     HiliteControl(theControl,10);                        /* Darken the button */
  833.     UnHiliteValue = 0;                                    /* To lighten the button */
  834.     RefCon = GetCRefCon(theControl);                    /* get control refcon */
  835.     
  836.     switch (RefCon)                                        /* Select correct button */
  837.         {
  838.         $$Loop Control.type = Button
  839.         $$if Control.HasLinks
  840.         case ResC_$Control.name$:                    /* Button, $Control.FullName$ */
  841.             $$Link    Control.Select
  842.             break;
  843.         $$endif
  844.         $$EndLoop Control.type = Button
  845.         $$Loop Control.type = HotRect
  846.         $$if Control.HasLinks
  847.         $$if Control.HotSpot
  848.         case ResC_$Control.name$:                    /* HotSpot, $Control.FullName$ */
  849.             $$Link    Control.Select
  850.             break;
  851.         $$endif Control.HotSpot
  852.         $$endif
  853.         $$EndLoop Control.type = HotRect
  854.         $$Loop Control.type = Icon
  855.         $$if Control.HasLinks
  856.         $$if Control.NonGraphic
  857.         case ResC_$Control.name$:                    /* Icon, $Control.FullName$ */
  858.             $$Link    Control.Select
  859.             break;
  860.         $$endif Control.NonGraphic
  861.         $$endif
  862.         $$EndLoop Control.type = Icon
  863.         $$Loop Control.type = Sicn
  864.         $$if Control.HasLinks
  865.         $$if Control.NonGraphic
  866.         case ResC_$Control.name$:                    /* Sicn, $Control.FullName$ */
  867.             $$Link    Control.Select
  868.             break;
  869.         $$endif Control.NonGraphic
  870.         $$endif
  871.         $$EndLoop Control.type = Sicn
  872.         $$Loop Control.type = Picture
  873.         $$if Control.HasLinks
  874.         $$if Control.NonGraphic
  875.         case ResC_$Control.name$:                    /* Picture, $Control.FullName$ */
  876.             $$Link    Control.Select
  877.             break;
  878.         $$endif Control.NonGraphic
  879.         $$endif
  880.         $$EndLoop Control.type = Picture
  881.         $$Loop Control.type = UButton
  882.         $$if Control.HasLinks
  883.         case ResC_$Control.name$:                    /* Plugin Button, $Control.FullName$ */
  884.             $$Link    Control.Select
  885.             break;
  886.         $$endif
  887.         $$EndLoop Control.type = UButton
  888.         $$Loop Control.type = Popup
  889.         case ResC_$Control.name$:                    /* PopUp, $Control.FullName$ */
  890.             theSelection = GetCtlValue(theWS->Ctrl_$Control.name$);    /* Get the Popup selection value */
  891.             switch (theSelection)                    /* Select correct item */
  892.                 {
  893.                 $$Loop PopupItems
  894.                 case $Control.PopupID$:                /* $Control.PopupID$, for $Control.PopupName$ */
  895.                     break;
  896.                 $$EndLoop PopupItems
  897.     
  898.                 default:                            /* allow other buttons, trap for debug */
  899.                     break;                            /* end of otherwise */
  900.                 }                                    /* end of switch */
  901.             break;
  902.         $$EndLoop Control.type = Popup
  903.         $$Loop Control.type = Palette
  904.         case ResC_$Control.name$:                /* Tool palette, $Control.FullName$ */
  905.             theWS->Value_$Control.name$ = GetCtlValue(theWS->Ctrl_$Control.name$);/* Get the palette value, 0xrrcc, rr is row, cc is column */
  906.             break;
  907.         $$EndLoop Control.type = Palette
  908.     
  909.         default:                                    /* allow other buttons, trap for debug */
  910.             break;                                /* end of otherwise */
  911.         }                                            /* end of switch */
  912.     
  913.     U_DoButton$Worksheet.name$(theWS,RefCon,theControl,&UnHiliteValue);/* Call to handle any extra user buttons */
  914.     
  915.     HiliteControl(theControl,UnHiliteValue);            /* Lighten the button */
  916.     }
  917.  
  918. }                                                    /* End of Handle a button being pressed */
  919.  
  920. $$if Worksheet.CheckboxesOrRadios
  921. /* ======================================================= */
  922.  
  923. static void Do_A_Checkbox($Worksheet.name$RecPtr theWS,ControlHandle theControl)/* Handle a checkbox being pressed */
  924. {
  925. long    RefCon;                                        /* RefCon for controls */
  926. short    theValue;                                    /* Current value of a control */
  927.  
  928.  
  929. if (theWS != nil)
  930.     {
  931.     RefCon = GetCRefCon(theControl);                    /* get control refcon */
  932.     theValue = GetCtlValue(theControl);                    /* Get current value */
  933.     theValue = (theValue + 1) & 1;                        /* Change value from 1 to 0 or from 0 to 1 */
  934.     
  935.     U_DoCheckbox$Worksheet.name$(theWS,theControl,&theValue);    /* Call user routine, allow changing value */
  936.     
  937.     switch (RefCon)                                        /* Select correct control */
  938.         {
  939.         $$Loop Control.type = Checkbox
  940.         case ResC_$Control.name$:                        /* Checkbox, $Control.FullName$  */
  941.             SetCtlValue(theControl, theValue);            /* Set checkbox to new value  */
  942.             theWS->Value_$Control.name$ = theValue;
  943.             $$if Control.HasLinks
  944.             if (theValue == 0)
  945.                 {
  946.                 $$Link    Control.Deselect
  947.                 }
  948.             else
  949.                 {
  950.                 $$Link    Control.Select
  951.                 }
  952.             $$endif
  953.             break;
  954.         $$EndLoop Control.type = Checkbox
  955.         $$Loop Control.type = UToggle
  956.         case ResC_$Control.name$:                        /* Plugin Toggle, $Control.FullName$  */
  957.             SetCtlValue(theControl, theValue);            /* Set checkbox to new value  */
  958.             theWS->Value_$Control.name$ = theValue;
  959.             $$if Control.HasLinks
  960.             if (theValue == 0)
  961.                 {
  962.                 $$Link    Control.Deselect
  963.                 }
  964.             else
  965.                 {
  966.                 $$Link    Control.Select
  967.                 }
  968.             $$endif
  969.             break;
  970.         $$EndLoop Control.type = UToggle
  971.         $$Loop Control.type = Radio
  972.         case ResC_$Control.name$:                        /* Radio, $Control.FullName$  */
  973.             theWS->Value_$Control.name$ = 1;            /* Set the Radio value */
  974.             SetCtlValue(theControl,1);                    /* Select this Radio  */
  975.     
  976.             /* Clear other Radio values in this group */
  977.             $$Loop RadioGroup
  978.             SetCtlValue(theWS->Ctrl_$Control.name$,0);
  979.             theWS->Value_$Control.name$ = 0;            /* Clear other radio */
  980.             $$EndLoop RadioGroup
  981.             $$Link    Control.Select
  982.             break;
  983.         $$EndLoop Control.type = Radio
  984.     
  985.         default:                                    /* allow other checkboxes and radios, trap for debug */
  986.             break;                                    /* end of otherwise */
  987.         }                                            /* end of case */
  988.     }
  989.  
  990. }
  991.  
  992. $$endif
  993. /* ======================================================= */
  994.  
  995. /* Routine: Do_$Worksheet.name$ */
  996. /* Purpose: Handle action to our window, like controls */
  997.  
  998. void Do_$Worksheet.name$(EventRecord *myEvent)
  999. {
  1000. short            code;                            /* Location of event in window or controls */
  1001. WindowPtr        whichWindow;                    /* Window pointer where event happened */
  1002. Point            myPt;                            /* Point where event happened */
  1003. ControlHandle    theControl;                        /* Handle for a control */
  1004. $Worksheet.name$RecPtr        theWS;
  1005.  
  1006.  
  1007. theWS = nil;
  1008.  
  1009. code = FindWindow(myEvent->where,&whichWindow);    /* Get where in window and which window */
  1010.  
  1011. LocateInstance(whichWindow);
  1012.  
  1013. if (RecPtr_$Worksheet.name$ != nil)                    /* Only do if the window is us */
  1014.     {
  1015.     theWS = RecPtr_$Worksheet.name$;
  1016.  
  1017.     U_DoEvent$Worksheet.name$(theWS,myEvent);
  1018.  
  1019.     $$if HasEditLists
  1020.     if (myEvent->what == mouseDown)
  1021.         {
  1022.         myPt = myEvent->where;                    /* Get mouse position */
  1023.         GlobalToLocal(&myPt);                    /* Make it relative */
  1024.  
  1025.         $$Loop Control.type = EditText
  1026.         if (PtInRect(myPt,&theWS->TERect_$Control.name$))    /* Check for pressed in the TE  Edit Text  */
  1027.             {
  1028.             Activate_TE_Area(false,myPt,theWS->TE_$Control.name$,$Control.TextSize$,$Control.TextFont$,$Control.TextStyle$);
  1029.             whichWindow = NIL;                    /* Do not let anyone else handle it */
  1030.             }
  1031.  
  1032.         $$EndLoop Control.type = EditText
  1033.         $$Loop Control.type = List
  1034.         if (PtInRect(myPt,&theWS->ListRect_$Control.name$))
  1035.             {
  1036.             ClickInTheList(myPt,myEvent->modifiers,theWS->List_$Control.name$,$Control.TextSize$,$Control.TextFont$,$Control.TextStyle$,false);
  1037.             whichWindow = NIL;                    /* Do not let anyone else handle it */
  1038.             }
  1039.  
  1040.         $$EndLoop Control.type = List
  1041.         }
  1042.  
  1043.     $$endif HasEditLists
  1044.     if ((theWS->theWindow == whichWindow) && (code == inContent))    /* for our window */
  1045.         {
  1046.         myPt = myEvent->where;                    /* Get mouse position */
  1047.         GlobalToLocal(&myPt);                    /* Make it relative */
  1048.  
  1049.         code = FindControl(myPt,whichWindow,&theControl);    /* Get type of control */
  1050.  
  1051.         $$if Worksheet.Scrollbars
  1052.         if ((code == inUpButton) || (code == inDownButton) || (code == inThumb) ||  (code == inPageDown) || (code == inPageUp))
  1053.             Do_A_ScrollBar(theWS,code,theControl,myPt);/* Do scrollbars */
  1054.         else
  1055.         $$endif
  1056.         if (code != 0)                                /* Check type of control */
  1057.             code = TrackControl(theControl,myPt,(ControlActionUPP)-1);/* Track the control */
  1058.         if (code == inButton)
  1059.             Do_A_Button(theWS,theControl);            /* Do buttons */
  1060.         $$if Worksheet.CheckboxesOrRadios
  1061.         else if (code == inCheckBox)
  1062.             Do_A_Checkbox(theWS,theControl);        /* Do checkboxes and radios */
  1063.         $$endif
  1064.  
  1065.         }
  1066.     }
  1067. }
  1068.  
  1069. /* ======================================================= */
  1070. /* ======================================================= */
  1071. $$CloseFile
  1072. $$EndLoop
  1073.  
  1074.  
  1075.